package mysql

import "gorm.io/gorm"

type Order struct {
	gorm.Model
	UserId      int64  `gorm:"type:int;comment:用户id"`
	OrderSn     string `gorm:"type:char(36);unique;comment:订单号"`
	PayType     int64  `gorm:"type:tinyint(1);default:1;comment:支付类型:1:支付宝,2:微信"`
	PayTime     string `gorm:"type:datetime(3);comment:支付时间"`
	Amount      int64  `gorm:"type:int;comment:价格"`
	OrderStatus int64  `gorm:"type:tinyint(1);default:1;comment:订单状态:1:待支付,2:已支付,3已取消,4:已退款,5:已完成"`
}

func (o *Order) Create() error {
	return Db.Create(&o).Error
}
func (o *Order) UpdateOrder(OrderSn string, orderStatus int64) error {
	return Db.Model(&Order{}).Where("order_sn = ?", OrderSn).Update("order_status", orderStatus).Error
}
